package com.baitai.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baitai.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baitai.common.annotation.Log;
import com.baitai.common.core.controller.BaseController;
import com.baitai.common.core.domain.AjaxResult;
import com.baitai.common.enums.BusinessType;
import com.baitai.system.domain.ReceiveTask;
import com.baitai.system.service.IReceiveTaskService;
import com.baitai.common.utils.poi.ExcelUtil;
import com.baitai.common.core.page.TableDataInfo;

/**
 * 接取任务关系Controller
 * 
 * @author xx
 * @date 2024-07-20
 */
@RestController
@RequestMapping("/system/receiveTask")
public class ReceiveTaskController extends BaseController
{
    @Autowired
    private IReceiveTaskService receiveTaskService;

    /**
     * 查询接取任务关系列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ReceiveTask receiveTask)
    {
        startPage();
        List<ReceiveTask> list = receiveTaskService.selectReceiveTaskList(receiveTask);
        return getDataTable(list);
    }

    /**
     * 导出接取任务关系列表
     */
    @Log(title = "接取任务关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReceiveTask receiveTask)
    {
        List<ReceiveTask> list = receiveTaskService.selectReceiveTaskList(receiveTask);
        ExcelUtil<ReceiveTask> util = new ExcelUtil<ReceiveTask>(ReceiveTask.class);
        util.exportExcel(response, list, "接取任务关系数据");
    }

    /**
     * 获取接取任务关系详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(receiveTaskService.selectReceiveTaskById(id));
    }

    /**
     * 新增接取任务关系
     */
    @Log(title = "接取任务关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceiveTask receiveTask)
    {
        return toAjax(receiveTaskService.insertReceiveTask(receiveTask));
    }

    /**
     * 修改接取任务关系
     */
    @Log(title = "接取任务关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceiveTask receiveTask)
    {
        return toAjax(receiveTaskService.updateReceiveTask(receiveTask));
    }

    /**
     * 修改接取任务关系
     */
    @Log(title = "审批任务", businessType = BusinessType.UPDATE)
    @PostMapping("/auditTask")
    public AjaxResult auditTask(@RequestBody ReceiveTask receiveTask)
    {
        return toAjax(receiveTaskService.auditReceiveTask(SecurityUtils.getUserId(),receiveTask));
    }

    /**
     * 删除接取任务关系
     */
    @Log(title = "接取任务关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(receiveTaskService.deleteReceiveTaskByIds(ids));
    }
}
